<?php
/*
	插件概览
	分销插件主要显示哪些数据？
		1、基本数据
		分销订单总数 会员总数 分销商总数 
		分销订单近七天增长趋势折线图 会员数近七天增长折线图 分销商近七天增长折线图 
		分红总笔数/金额 结算总笔数/金额
		饼状图显示各状态分红数额  饼状图显示各状态结算总笔数/金额
		
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'welcome';
$tabs=array(
	array('op'=>'welcome','title'=>'概况'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='welcome'){
	//会员
	$member=array(
		'member'=>pdo_count('jy_weishop_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'])),
		'agent'=>pdo_count('jy_weishop_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'ispartner'=>1)),
		'apply'=>pdo_count('jy_weishop_member',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'partnerstatus'=>0,'ispartner'=>1)),
	);
	$return['htmls'][]=array('type'=>'data','one_num'=>3,'title'=>'会员概况','datas'=>array(
		array('title'=>'会员数量','num'=>1,'data'=>$member['member']),
		array('title'=>'股东数量','num'=>1,'data'=>$member['agent']),
		array('title'=>'待审核股东数量','num'=>1,'data'=>$member['apply']),
	));
	//分红
	$month_start=strtotime(date('Ym').'01');
	$commission_month['num']=$this->count('billp',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start));
	$commission_month['money']=$this->sum('billp',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start),'money');
	$commission['num']=$this->count('billp',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']));
	$commission['money']=$this->sum('billp',array('merchid'=>$_SESSION['onemerchid'],'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),'money');
	//结算
	$balance_month['num']=$this->count('bill',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start));
	$balance_month['money']=$this->sum('bill',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start),'bonusmoney_send');
	$balance['num']=$this->count('bill',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']));
	$balance['money']=$this->sum('bill',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),'bonusmoney_send');
	$return['htmls'][]=array('type'=>'data','one_num'=>3,'title'=>'分红概况','datas'=>array(
		array('title'=>'分红笔数/金额','num'=>2,'data'=>array($commission['num'],$commission['money'])),
		array('title'=>'结算笔数/金额','num'=>2,'data'=>array($balance['num'],$balance['money'])),
		array('title'=>'本月分红笔数/金额','num'=>2,'data'=>array($commission_month['num'],$commission_month['money'])),
		array('title'=>'本月结算笔数/金额','num'=>2,'data'=>array($balance_month['num'],$balance_month['money'])),
	));
	
	$commission_pie=array(
		'title'=>'分红概况',
		'tablename'=>$this->tablename('billp'),
		'width'=>'',
		'field'=>'status',
		'field_options'=>$this->commission_status,
		'params'=>array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),
	);
	$return['htmls'][]=model('core/echart')->pie($commission_pie);
	$balance_pie=array(
		'title'=>'结算订单概况',
		'tablename'=>$this->tablename('bill'),
		'width'=>'50%',
		'field'=>'status',
		'field_options'=>$this->balance_status,
		'params'=>array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),
	);
	$return['htmls'][]=model('core/echart')->pie($balance_pie);
	set_html('title','股东概况');
	exi($return);
}